package com.qianbao.service.coinrecord.impl;

import com.qianbao.components.excepion.CommonException;
import com.qianbao.components.uuid.SVUuidTool;
import com.qianbao.dao.coinrecord.CoinRecordDao;
import com.qianbao.domain.coinrecord.CoinRecordEntity;
import com.qianbao.service.coinrecord.CoinRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;


@Service
public class CoinRecordServiceImpl implements CoinRecordService {


    @Autowired
    private CoinRecordDao dao;

    @Override
    public List<CoinRecordEntity> findAllRecordList(CoinRecordEntity entity) throws CommonException {

        int pageNo = (entity.getPage_no() - 1) * entity.getPage_size();

        List<CoinRecordEntity> recordList = dao.findAllRecordList(
                entity.getCustom_id(),
                pageNo,
                entity.getPage_size());

        return recordList;
    }


    @Override
    public void saveCoinRecord(String custom_id, String coin_number, String coin_record_tip){

        CoinRecordEntity entity = new CoinRecordEntity();
        entity.setCustom_id(custom_id);
        entity.setCoin_number(coin_number);
        entity.setCoin_record_tip(coin_record_tip);
        entity.setCoin_record_id(SVUuidTool.getUUID());


        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        format.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        String currentTime = format.format(new Date());
        entity.setRecord_create_time(currentTime);

        dao.insertRecord(entity);

    }




}















